package cn.gdcp.lkqapp07;

import android.graphics.Bitmap;
import android.util.Log;
import android.util.LruCache;

import com.android.volley.toolbox.ImageLoader;

public class MyImageCache implements ImageLoader.ImageCache {
    private final String TAG = "MyImageCache";
    private LruCache<String,Bitmap> lruCache;

    public MyImageCache() {
        int maxsize = 10*1024*1024;
        lruCache = new LruCache<String, Bitmap>(maxsize){
            @Override
            protected int sizeOf(String key, Bitmap value) {
                return value.getRowBytes() * value.getHeight();
            }
        };

    }

    @Override
    public Bitmap getBitmap(String s) {
        Bitmap bitmap = lruCache.get(s);
        if (bitmap == null){
            Log.e(TAG, "getBitmap failed bitmap == null");
        }else{
            Log.e(TAG, "getBitmap success bitmap != null");
        }
        return bitmap;
    }

    @Override
    public void putBitmap(String s, Bitmap bitmap) {
        if (bitmap == null){
            Log.e(TAG, "getBitmap failed bitmap == null");
        }else{
            Log.e(TAG, "getBitmap success bitmap != null");
        }
        lruCache.put(s, bitmap);
    }
}
